package cn.bouncyslime.graduationProject.nba.controller;

import cn.bouncyslime.graduationProject.nba.service.PlayerDataService;
import cn.bouncyslime.graduationProject.nba.service.PlayerInfoService;
import cn.bouncyslime.graduationProject.nba.util.ResponseData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author 张一卓
 * @date 2020/4/4 1:52
 **/
@Controller
public class PlayerDataController {

    private static final Logger logger = LoggerFactory.getLogger(PlayerDataController.class);

    @Autowired
    PlayerDataService playerDataService;

    /**
     * 根据 playerId 查询该球员的所有常规赛数据，包括，场均，总计，单场最高，进阶数据
     * @param modelMap
     * @param playerId
     * @return
     */
    @RequestMapping(value = "listPlayerRegularData", method = {RequestMethod.GET, RequestMethod.POST})
    public String listPlayerRegularData(ModelMap modelMap, @RequestParam String playerId){
        ResponseData responseData = playerDataService.listPlayerRegularData(Integer.valueOf(playerId));
        modelMap.addAttribute(responseData);
        modelMap.addAttribute("playerId", playerId);
        return "rsPlayerData";
    }

    @RequestMapping(value = "listPlayerPostData", method = {RequestMethod.GET, RequestMethod.POST})
    public String listPlayerPostData(ModelMap modelMap, @RequestParam String playerId){
        ResponseData responseData = playerDataService.listPlayerPostData(Integer.valueOf(playerId));
        modelMap.addAttribute(responseData);
        modelMap.addAttribute("playerId", playerId);
        return "psPlayerData";
    }

    /**
     * 跳转到 图表 模式
     * @param modelMap
     * @param playerId
     * @param type
     * @return
     */
    @RequestMapping(value = "toRSChartPattern", method = {RequestMethod.GET, RequestMethod.POST})
    public String toRSChartPattern(ModelMap modelMap, @RequestParam Integer playerId, @RequestParam String type){
        modelMap.addAttribute("playerId", playerId);
        modelMap.addAttribute("type", type);
        return "rsCharts";
    }

    /**
     * 跳转到 图表 模式
     * @param modelMap
     * @param playerId
     * @param type
     * @return
     */   @RequestMapping(value = "toPSChartPattern", method = {RequestMethod.GET, RequestMethod.POST})
    public String toPSChartPattern(ModelMap modelMap, @RequestParam Integer playerId, @RequestParam String type){
        modelMap.addAttribute("playerId", playerId);
        modelMap.addAttribute("type", type);
        return "psCharts";
    }

    /**
     * 根据 playerId 和 type 来获取该球员的所有 场均 或 总计 或 单场 或 进阶 数据
     * @param modelMap
     * @param playerId
     * @param type
     * @return
     */
    @RequestMapping(value = "toRSTablePattern", method = {RequestMethod.GET, RequestMethod.POST})
    public String toRSTablePattern(ModelMap modelMap, @RequestParam Integer playerId, @RequestParam String type){
        ResponseData responseData = null;
        if ("avg".equals(type)){
            responseData = playerDataService.listRSPlayerAveragingData(playerId);
        }else if ("sum".equals(type)){
            responseData = playerDataService.listRSPlayerSummaryData(playerId);
        }else if("basicAdv".equals(type)){
            responseData = playerDataService.listRSPlayerBasicAdvData(playerId);
        }else if ("shootingAdv".equals(type)){
            responseData = playerDataService.listRSPlayerShootingAdvData(playerId);
        }
        modelMap.addAttribute(responseData);
        modelMap.addAttribute("playerId", playerId);
        modelMap.addAttribute("type", type);
//        logger.debug(responseData.toString());
        return "rsTables";
    }

    /**
     * 根据 playerId 和 type 来获取该球员的所有 场均 或 总计 或 单场 或 进阶 数据
     * @param modelMap
     * @param playerId
     * @param type
     * @return
     */
    @RequestMapping(value = "toPSTablePattern", method = {RequestMethod.GET, RequestMethod.POST})
    public String toPSTablePattern(ModelMap modelMap, @RequestParam Integer playerId, @RequestParam String type){
        ResponseData responseData = null;
        if ("avg".equals(type)){
            responseData = playerDataService.listPSPlayerAveragingData(playerId);
        }else if ("sum".equals(type)){
            responseData = playerDataService.listPSPlayerSummaryData(playerId);
        }else if("basicAdv".equals(type)){
            responseData = playerDataService.listPSPlayerBasicAdvData(playerId);
        }else if ("shootingAdv".equals(type)){
            responseData = playerDataService.listPSPlayerShootingAdvData(playerId);
        }
        modelMap.addAttribute(responseData);
        modelMap.addAttribute("playerId", playerId);
        modelMap.addAttribute("type", type);
//        logger.debug(responseData.toString());
        return "psTables";
    }

    /**
     * 加载 playerId 球员的 dataType 场均 数据，用作 画图 数据
     * @param map
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "listPlayerAvgDataAllSeason", method = {RequestMethod.POST})
    public ResponseData listPlayerAvgDataAllSeason(@RequestBody Map<String, String> map){
        String dataType = map.get("dataType");
        Integer playerId = Integer.valueOf(map.get("playerId"));
        String gameType = map.get("gameType");
        ResponseData responseData = null;
        if ("regular".equals(gameType)){
            if ("score".equals(dataType)){
                responseData = playerDataService.listRSPlayerAvgScoreAllSeason(playerId);
            }else if ("percentage".equals(dataType)){
                responseData = playerDataService.listRSPlayerAvgPercentageAllSeason(playerId);
            }else if ("amount".equals(dataType)){
                responseData = playerDataService.listRSPlayerAvgAmountAllSeason(playerId);
            }else if ("attempts".equals(dataType)){
                responseData = playerDataService.listRSPlayerAvgAttemptsAllSeason(playerId);
            }else if("rebound".equals(dataType)){
                responseData = playerDataService.listRSPlayerAvgReboundAllSeason(playerId);
            }else{
                responseData = playerDataService.listRSPlayerAvgOtherDataAllSeason(playerId);
            }
        }else if("post".equals(gameType)){
            if ("score".equals(dataType)){
                responseData = playerDataService.listPSPlayerAvgScoreAllSeason(playerId);
            }else if ("percentage".equals(dataType)){
                responseData = playerDataService.listPSPlayerAvgPercentageAllSeason(playerId);
            }else if ("amount".equals(dataType)){
                responseData = playerDataService.listPSPlayerAvgAmountAllSeason(playerId);
            }else if ("attempts".equals(dataType)){
                responseData = playerDataService.listPSPlayerAvgAttemptsAllSeason(playerId);
            }else if("rebound".equals(dataType)){
                responseData = playerDataService.listPSPlayerAvgReboundAllSeason(playerId);
            }else{
                responseData = playerDataService.listPSPlayerAvgOtherDataAllSeason(playerId);
            }
        }
        return responseData;
    }

    @ResponseBody
    @RequestMapping(value = "listPlayerSumDataAllSeason", method = {RequestMethod.POST})
    public ResponseData listPlayerSumDataAllSeason(@RequestBody Map<String, String> map){
        String dataType = map.get("dataType");
        Integer playerId = Integer.valueOf(map.get("playerId"));
        String gameType = map.get("gameType");
        ResponseData responseData = null;
        if ("regular".equals(gameType)){
            if ("percentage".equals(dataType)){
                responseData = playerDataService.listRSPlayerSumPercentageAllSeason(playerId);
            }else if ("amount".equals(dataType)){
                responseData = playerDataService.listRSPlayerSumAmountAllSeason(playerId);
            }else if ("attempts".equals(dataType)){
                responseData = playerDataService.listRSPlayerSumAttemptsAllSeason(playerId);
            }else if("rebound".equals(dataType)){
                responseData = playerDataService.listRSPlayerSumReboundAllSeason(playerId);
            }else{
                responseData = playerDataService.listRSPlayerSumOtherDataAllSeason(playerId);
            }
        }else if("post".equals(gameType)){
            if ("percentage".equals(dataType)){
                responseData = playerDataService.listPSPlayerSumPercentageAllSeason(playerId);
            }else if ("amount".equals(dataType)){
                responseData = playerDataService.listPSPlayerSumAmountAllSeason(playerId);
            }else if ("attempts".equals(dataType)){
                responseData = playerDataService.listPSPlayerSumAttemptsAllSeason(playerId);
            }else if("rebound".equals(dataType)){
                responseData = playerDataService.listPSPlayerSumReboundAllSeason(playerId);
            }else{
                responseData = playerDataService.listPSPlayerSumOtherDataAllSeason(playerId);
            }
        }
//        logger.debug(responseData.toString());
        return responseData;
    }

    @ResponseBody
    @RequestMapping(value = "listPlayerBasicAdvDataAllSeason", method = {RequestMethod.POST})
    public ResponseData listPlayerBasicAdvDataAllSeason(@RequestBody Map<String, String> map){
//        logger.debug(map.toString());
        String dataType = map.get("dataType");
        Integer playerId = Integer.valueOf(map.get("playerId"));
        String gameType = map.get("gameType");
        ResponseData responseData = null;
        if ("regular".equals(gameType)){
            if ("reboundRate".equals(dataType)){
                responseData = playerDataService.listRSPlayerBasicAdvReboundRateAllSeason(playerId);
            }else if ("winShare".equals(dataType)){
                responseData = playerDataService.listRSPlayerBasicAdvWinShareAllSeason(playerId);
            }else if("efficiency".equals(dataType)){
                responseData = playerDataService.listRSPlayerBasicAdvEfficiencyAllSeason(playerId);
            }else{
                responseData = playerDataService.listRSPlayerBasicAdvOtherAllSeason(playerId);
            }
        }else if("post".equals(gameType)){
            if ("reboundRate".equals(dataType)){
                responseData = playerDataService.listPSPlayerBasicAdvReboundRateAllSeason(playerId);
            }else if ("winShare".equals(dataType)){
                responseData = playerDataService.listPSPlayerBasicAdvWinShareAllSeason(playerId);
            }else if("efficiency".equals(dataType)){
                responseData = playerDataService.listPSPlayerBasicAdvEfficiencyAllSeason(playerId);
            }else{
                responseData = playerDataService.listPSPlayerBasicAdvOtherAllSeason(playerId);
            }
        }
//        logger.debug(responseData.toString());
        return responseData;
    }


    @ResponseBody
    @RequestMapping(value = "listPlayerShootingAdvDataAllSeason", method = {RequestMethod.POST})
    public ResponseData listPlayerShootingAdvDataAllSeason(@RequestBody Map<String, String> map){
//        logger.debug(map.toString());
        String dataType = map.get("dataType");
        Integer playerId = Integer.valueOf(map.get("playerId"));
        String gameType = map.get("gameType");
        ResponseData responseData = null;
        if ("regular".equals(gameType)){
            if ("percentage".equals(dataType)){
                responseData = playerDataService.listRSPlayerShootingAdvPercentageAllSeason(playerId);
            }else if ("amount".equals(dataType)){
                responseData = playerDataService.listRSPlayerShootingAdvAmountAllSeason(playerId);
            }else if("attempts".equals(dataType)){
                responseData = playerDataService.listRSPlayerShootingAdvAttemptsAllSeason(playerId);
            }else if("proportion".equals(dataType)){
                responseData = playerDataService.listRSPlayerShootingAdvProportionAllSeason(playerId);
            }else {
                responseData = playerDataService.listRSPlayerShootingAdvOtherAllSeason(playerId);
            }
        }else if("post".equals(gameType)){
            if ("percentage".equals(dataType)){
                responseData = playerDataService.listPSPlayerShootingAdvPercentageAllSeason(playerId);
            }else if ("amount".equals(dataType)){
                responseData = playerDataService.listPSPlayerShootingAdvAmountAllSeason(playerId);
            }else if("attempts".equals(dataType)){
                responseData = playerDataService.listPSPlayerShootingAdvAttemptsAllSeason(playerId);
            }else if("proportion".equals(dataType)){
                responseData = playerDataService.listPSPlayerShootingAdvProportionAllSeason(playerId);
            }else {
                responseData = playerDataService.listPSPlayerShootingAdvOtherAllSeason(playerId);
            }
        }
//        logger.debug(responseData.toString());
        return responseData;
    }

    @RequestMapping(value = "listPlayerRSTopTenData", method = {RequestMethod.POST, RequestMethod.GET})
    public String listPlayerRSTopTenData(ModelMap modelMap, @RequestParam String dataType, @RequestParam String type){
        List<Map<String, Object>> list = null;
        if ("sum".equals(type)){
            if ("score".equals(dataType)){
                list = playerDataService.listRSTopTenSumScore();
            }else if ("assists".equals(dataType)){
                list = playerDataService.listRSTopTenSumAssists();
            }else if ("steal".equals(dataType)){
                list = playerDataService.listRSTopTenSumSteal();
            }else if ("rebound".equals(dataType)){
                list = playerDataService.listRSTopTenSumRebound();
            }else if ("fault".equals(dataType)){
                list = playerDataService.listRSTopTenSumFault();
            }else if ("foul".equals(dataType)){
                list = playerDataService.listRSTopTenSumFoul();
            }else if ("blockShot".equals(dataType)){
                list = playerDataService.listRSTopTenSumBlockShot();
            }
        }else if("avg".equals(type)){
            if ("score".equals(dataType)){
                list = playerDataService.listRSTopTenAvgScore();
            }else if ("assists".equals(dataType)){
                list = playerDataService.listRSTopTenAvgAssists();
            }else if ("steal".equals(dataType)){
                list = playerDataService.listRSTopTenAvgSteal();
            }else if ("rebound".equals(dataType)){
                list = playerDataService.listRSTopTenAvgRebound();
            }else if ("fault".equals(dataType)){
                list = playerDataService.listRSTopTenAvgFault();
            }else if ("foul".equals(dataType)){
                list = playerDataService.listRSTopTenAvgFoul();
            }else if ("blockShot".equals(dataType)){
                list = playerDataService.listRSTopTenAvgBlockShot();
            }
        }else if ("single".equals(type)){
            if ("score".equals(dataType)){
                list = playerDataService.listRSTopTenSingleScore();
            }else if ("assists".equals(dataType)){
                list = playerDataService.listRSTopTenSingleAssists();
            }else if ("steal".equals(dataType)){
                list = playerDataService.listRSTopTenSingleSteal();
            }else if ("rebound".equals(dataType)){
                list = playerDataService.listRSTopTenSingleRebound();
            }else if ("fault".equals(dataType)){
                list = playerDataService.listRSTopTenSingleFault();
            }else if ("foul".equals(dataType)){
                list = playerDataService.listRSTopTenSingleFoul();
            }else if ("blockShot".equals(dataType)){
                list = playerDataService.listRSTopTenSingleBlockShot();
            }
        }
        modelMap.addAttribute("data", list);
        return "playerTopData";
    }
}
